<template>
  <el-aside class="sidebar" :width="width">
    <!-- 页面LOGO -->
    <div class="sidebar-logo">
      <span class="sidebar-logo-text">后台管理系统</span>
      <!-- <img src="../../assets/img/qq_speed1.jpg" alt v-show="!isClose"> -->
    </div>
    <!-- 页面菜单 -->
    <el-menu class="menu" v-show="!isClose" :default-active="defaultActive">
      <!-- 循环显示一级菜单 -->
      <el-menu-item
        class="menu-tab"
        v-for="(value, index) in pageList"
        :key="index"
        :index="'/' + value.link"
        :style="tabStyle()"
      >
        <span slot="title">
          <router-link class="link_style" :to="value.link">{{
            value.name
          }}</router-link>
        </span>
      </el-menu-item>
    </el-menu>
  </el-aside>
</template>

<script>
export default {
  name: "view-menu",
  data() {
    return {
      // 菜单结构
      pageList: [
        {
          name: "数据可视化",
          link: "/visual",
        },
        {
          name: "贴子列表",
          link: "/tie",
        },
        {
          name: "分类列表",
          link: "/lei",
        },
      ],
      // 默认宽度
      defaultWidth: 250,
      // 实时宽度
      width: "150px",
      // 关闭状态
      isClose: false,
    };
  },
  // 计算变量
  computed: {
    // 菜单选中
    defaultActive() {
      return this.$route.path;
    },
  },
  methods: {
    // 可跳转tab样式
    tabStyle() {
      return {
        paddingLeft: "20px",
      };
    },
    // 更改右侧home参数
    showSelf(id) {
      return `/home/${id}`;
    },
  },
};
</script>

<style lang="scss" scoped>
.sidebar {
  position: relative;
  // height: 100%;
  background-color: rgba(9, 34, 45, 0.4);
  box-shadow: 3px 10px 10px rgba(0, 0, 0, 0.3);
  overflow: unset;
  // transition: all 0.1s;
  z-index: 10;
  .sidebar-logo {
    text-align: center;
    img {
      height: 30px;
      border-radius: 50%;
    }
    .sidebar-logo-text {
      display: inline-block;
      padding-top: 20px;
      padding-bottom: 20px;
      color: #fff;
    }
  }
  .link_style {
    margin-left: -20px;
    margin-right: -20px;
    padding: 0 20px;
  }
}

.close {
  position: absolute;
  left: 100%;
  top: 0;
  width: 40px;
  height: 40px;
  line-height: 40px;
  text-align: center;
  font-size: 20px;
  color: #38baf3;
  background: rgba(9, 34, 45, 0.4);
  border: none;
  border-radius: 0 5px 5px 0;
  padding: 0;
}

.close >>> i {
  display: block;
  height: 100%;
  line-height: inherit;
}

.close:hover,
.close:focus {
  background: rgba(9, 34, 45, 0.4);
  color: #38baf3;
}

img {
  margin-top: 20px;
  margin-bottom: 20px;
  cursor: pointer;
}

.menu {
  width: 100%;
  text-align: left;
  font-size: 20px;
  background-color: rgba(9, 34, 45, 0);
  border: none;
}

.menu /deep/ .el-submenu__title {
  height: 37px;
  line-height: 37px;
  color: white;
}

.menu /deep/ .el-submenu__title i {
  color: #38baf3;
}

.menu /deep/ .el-submenu__title:hover {
  background: rgba(5, 31, 58, 0.2);
  border-left: 3px solid #38baf3;
}

.menu-expand /deep/ .el-menu {
  background-color: rgba(255, 0, 0, 0);
}

.menu-expand /deep/ .el-menu-item-group__title {
  padding: 0;
}

.menu /deep/ .menu-tab {
  height: 37px;
  line-height: 37px;
  padding-left: 35px;
  color: #e2e3e5;
}

.menu-tab:hover,
.is-active[tabindex="-1"] {
  color: #38baf3;
  border-left: 3px solid #38baf3;
  background: rgba(5, 31, 58, 0.2);
}

.menu-tab:focus {
  background: rgba(5, 31, 58, 0.2);
}

.el-menu-item * {
  display: block;
}
</style>
